from django import forms
from app.models import User
from bootstrap_toolkit.widgets import BootstrapDateInput,BootstrapTextInput,BootstrapUneditableInput
from captcha.fields import CaptchaField
class LoginForm(forms.Form):
    username = forms.CharField(
            required = True,
            label=u"邮箱",
            error_messages={'required':'请输入用户名'},
            widget=forms.TextInput(
                attrs={
                    'placeholder':u"用户名",
                    }
                )
            )

    password = forms.CharField(
            required=True,
            label=u"密码",
            error_messages={'required':u'请输入密码'},
            widget=forms.PasswordInput(
                attrs={
                    'placeholder':u"密码",
                    }
                ),
            )

    def clean(self):
        if not self.is_valid():
            raise forms.ValidationError(u"邮箱和密码为必填项")
        else:
            cleaned_data = super(LoginForm,self).clean()

class RegisterForm(forms.Form):
    email= forms.CharField(
        required=True,
        label=u"邮箱",
        error_messages={'required': '请输入邮箱'},
        widget=forms.TextInput(
            attrs={
                'placeholder': u"邮箱",
            }
        )
    )
    username = forms.CharField(
        required=True,
        label=u"用户名",
        error_messages={'required': '请输入用户名'},
        widget=forms.TextInput(
            attrs={
                'placeholder': u"用户名",
            }
        )
    )
    password1 = forms.CharField(
        required=True,
        label=u"密码",
        error_messages={'required': u'请输入密码'},
        widget=forms.PasswordInput(
            attrs={
                'placeholder': u"密码",
            }
        ),
    )
    password2= forms.CharField(
        required=True,
        label=u"密码",
        error_messages={'required': u'请确认密码'},
        widget=forms.PasswordInput(
            attrs={
                'placeholder': u"密码",
            }
        ),

    )
    captcha=CaptchaField(error_messages={"invalid": u"验证码错误"})
    def clean(self):
        # if not self.is_valid():
        #     raise forms.ValidationError(u"邮箱和密码为必填项")
        # else:
        #     cleaned_data = super(RegisterForm, self).clean()
        if  self.is_valid() :
            cleaned_data = super(RegisterForm, self).clean()
            if cleaned_data["password1"]!=cleaned_data["password2"]:
                raise forms.ValidationError(u"两次输入密码不一致")
    pass
class ArticleForm(forms.Form):
    id=forms.CharField(required=False)
    publishdate=forms.DateTimeField(required=False)
    updatedate=forms.DateTimeField(required=False)
    tag=forms.CharField(required=False)
    userid=forms.CharField(required=False)
    username=forms.CharField(required=False)
    isdelete = forms.BooleanField(required=False)
    deleteddate = forms.DateTimeField(required=False)
    title=forms.Textarea()
    author=forms.Textarea()#作者
    Money_reward=forms.CharField(required=False)#赏金
    deposit=forms.BooleanField(required=False)#是否赏金已托管
    content=forms.Textarea()
    status=forms.CharField(required=False)
    type=forms.CharField(required=False)#提问类别
    tag=forms.Textarea()
    tag0=forms.Textarea()
    tag1=forms.Textarea()
    tag2=forms.Textarea()
    tag3=forms.Textarea()
    tag4=forms.Textarea()
    pass